using Headspring.Training.Core.Services;

namespace Headspring.Training.Core.Model.StateCommands
{
	public class DraftToAssignedCommand : StateCommandBase
	{
		private readonly ICalendar _calendar;

		public DraftToAssignedCommand(WorkOrder workOrder, Employee currentUser,
		                              ICalendar calendar)
			: base(workOrder, currentUser)
		{
			_calendar = calendar;
		}

		public override string TransitionVerbPresentTense
		{
			get { return "Assign"; }
		}

		public override string TransitionVerbPastTense
		{
			get { return "Assigned"; }
		}

		public override WorkOrderStatus GetBeginStatus()
		{
			return WorkOrderStatus.Draft;
		}

		protected override WorkOrderStatus GetEndStatus()
		{
			return WorkOrderStatus.Assigned;
		}

		protected override bool userCanExecute(Employee currentUser)
		{
			return currentUser == _workOrder.Creator;
		}

		protected override void preExecute(IStateCommandVisitor commandVisitor)
		{
			_calendar.GetCurrentTime();
		}

		protected override void postExecute(IStateCommandVisitor commandVisitor)
		{
			commandVisitor.EditWorkOrder(_workOrder);
		}
	}
}